﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dao
{
    public class IPProductoProcesoElaboracion :Intermediario
    {
        public override void save<T>(T entity)
        {
            try
            {
                ProductoProcesoElaboracion ct = entity as ProductoProcesoElaboracion;
                dao.ProductoProcesoElaboracions.InsertOnSubmit(ct);
            }
            catch (Exception ex)
            {
                throw new Exception("IPRProductoProcesoElaboracion.save - " + ex.Message);
            }
        }

        public override List<T> getAll<T>()
        {
            return (from ppe in dao.ProductoProcesoElaboracions where ppe.Activo == true select ppe).ToList() as List<T>;
        }

        public override List<T> getByCriterio<T>(string att, string op, string val)
        {
            throw new NotImplementedException();
        }

        public override IList<T> getCriterioById<T>(string att, string op, int val)
        {
            throw new NotImplementedException();
        }

        public override object getPorId(int id)
        {
            throw new NotImplementedException();
        }

        public override IList<T> getPorCriterio<T>(string name)
        {
            throw new NotImplementedException();
        }

        public override void Update<T>(T entity)
        {
            throw new NotImplementedException();
        }

        public override void Delete(int id)
        {
            try
            {
                var ct = (from c in dao.ProductoProcesoElaboracions where c.IdPPE == id select c).SingleOrDefault();

                if (ct != null)
                {
                    ct.Activo = false;
                   // dao.ProductoProcesoElaboracions.DeleteOnSubmit(ct);
                    dao.SubmitChanges();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
